package com.njh.kaleidoscope.common.file.utils;

import android.graphics.Bitmap;

import com.apkfuns.logutils.LogUtils;
import com.jh.tools.common.file.FileUtils;
import com.jh.tools.common.file.PATH;
import com.jh.tools.common.file.SDUtils;

import java.io.File;

/**
 * Created by niejiahuan on 2016/5/31.
 */
public class FileManageImpl extends FileManage {
    private FileUtils mFileUtils;
    public FileManageImpl(){
        this.mFileUtils=new FileUtils();
    }


    /**
     * 文件保存
     *
     * @param path 文件路径
     * @param File 文件流
     */
    @Override
    void keepFile(String path, File File) {
        if (SDUtils.getInstance().externalMemoryAvailable()){
            this.mFileUtils.saveFile(path,File);
        }else {
            LogUtils.e("not find SD");
        }
    }

    /**
     * 保存图片文件
     *
     * @param fPath   文件所在路径
     * @param ImgName 文件名称
     * @return
     */
    @Override
    public File keepImg(String fPath, String ImgName) {
        File file=null;
        if (SDUtils.getInstance().externalMemoryAvailable()) {
            file = new File(fPath);
            if (file.exists()) {
                keepFile(PATH.getImageDir() + ImgName, file);
            }

        }else {
            LogUtils.e("not find SD");
        }
        return file;
    }

    @Override
    public File keepImg(Bitmap bitmap, String ImgName) {
        if (SDUtils.getInstance().externalMemoryAvailable()) {
            return this.mFileUtils.saveFile(bitmap,PATH.getImageDir()+ImgName);
        }else {
            LogUtils.e("not find SD");
            return null;
        }
    }
}
